package D240509.extension;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

import java.io.IOException;

public class JsoupUtil {
    public static Elements getElements(Web web) throws IOException {
        Document doc = Jsoup.connect(web.setUrl()).get();
        Elements elements = doc.getElementsByClass("subject_t");
        return elements;
    }

    public static String show(String keyword, Elements elements) throws IOException {
        String msg = "获取到信息：\n";
        for (int i = 0; i < elements.size(); i++) {
            if (elements.get(i).text().contains(keyword)) {
                /*System.out.println("标题：" + elements.get(i).text());
                System.out.println("网址：https://bbs2.xmfish.com/" + elements.get(i).attr("href"));*/
                msg += "标题：" + elements.get(i).text() + "\n网址：https://bbs2.xmfish.com/" + elements.get(i).attr("href") + "\n";
            }
        }
        return msg;
    }


}
